home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group9]VCL Source Standard / ivsuseld.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-12  |  4.9 KB  |  218 lines

  1. unit IvSuSeld;
  2.  
  3. {$I IVMULTI.INC}
  4.  
  5. interface
  6.  
  7. uses
  8. {$IFDEF WIN32}
  9.   Windows,
  10. {$ELSE}
  11.   WinTypes, WinProcs,
  12. {$ENDIF}               
  13.   Classes, Graphics, Forms, Controls, Buttons, StdCtrls,
  14.   IvDictio, IvMlCtrl, IvMulti;
  15.  
  16. type
  17.   TIvSubLanguageSelectDialog = class(TForm)
  18.     ListBox: TIvListBox;
  19.     CancelButton: TButton;
  20.     OkButton: TButton;
  21.     Translator: TIvTranslator;
  22.     HelpButton: TButton;
  23.     procedure ListBoxDblClick(Sender: TObject);
  24.     procedure HelpButtonClick(Sender: TObject);
  25.     procedure FormActivate(Sender: TObject);
  26.  
  27.   protected
  28.     function GetLocale: Integer;
  29.  
  30.   public
  31.     constructor CreateParam(
  32.       owner: TComponent;
  33.       dictionary: TIvDictionary;
  34.       const msg: String;
  35.       options: TIvLanguageDialogOptions;
  36.       helpContext: THelpContext);
  37.  
  38.     property Locale: Integer read GetLocale;
  39.   end;
  40.  
  41.   function SelectSublanguage(
  42.     parent: TControl;
  43.     dictionary: TIvDictionary;
  44.     const msg: String;
  45.     options: TIvLanguageDialogOptions;
  46.     helpContext: THelpContext;
  47.     var langId: Integer): Boolean;
  48.  
  49. implementation
  50.  
  51. uses
  52.   SysUtils;
  53.  
  54. {$R *.DFM}
  55.  
  56. function SelectSublanguage(
  57.   parent: TControl;
  58.   dictionary: TIvDictionary;
  59.   const msg: String;
  60.   options: TIvLanguageDialogOptions;
  61.   helpContext: THelpContext;
  62.   var langId: Integer): Boolean;
  63. var
  64.   dialog: TIvSubLanguageSelectDialog;
  65. begin
  66.   if not dictionary.IsOpen then
  67.     raise EIvMulti.Create(
  68.       'Dictionary is not open' +
  69.       #10#13'You must open the dictionary before you can change the language');
  70.  
  71.   Result := False;
  72.   dialog := TIvSubLanguageSelectDialog.CreateParam(
  73.     nil,
  74.     dictionary,
  75.     msg,
  76.     options,
  77.     helpContext);
  78.  
  79.   if not (ivloNoCenter in options) then
  80.     IvCenterControl(parent, dialog);
  81.  
  82.   if dialog.ShowModal = mrOk then
  83.   begin
  84.     langId := dialog.Locale;
  85.     Result := True;
  86.   end;
  87.   dialog.Free;
  88. end;
  89.  
  90. constructor TIvSubLanguageSelectDialog.CreateParam(
  91.   owner: TComponent;
  92.   dictionary: TIvDictionary;
  93.   const msg: String;
  94.   options: TIvLanguageDialogOptions;
  95.   helpContext: THelpContext);
  96. var
  97.   i, j, k, first, langId: Integer;
  98.   found: Boolean;
  99.   locales: TList;
  100.   subs: TStringList;
  101.   displayName: TIvDisplayName;
  102.   language: TIvLanguage;
  103.   locale: TIvLocale;
  104. begin
  105.   inherited Create(owner);
  106.  
  107.   if msg <> '' then
  108.     Caption := msg;
  109.  
  110.   Self.HelpContext := helpContext;
  111.  
  112.   Translator.Dictionary := dictionary;
  113.   Translator.Translate;
  114.  
  115.   { Gets the sub language ids }
  116.  
  117.   if dictionary.Languages[0].Primary = LANG_NEUTRAL then
  118.     first := 1
  119.   else
  120.     first := 0;
  121.  
  122.   Screen.Cursor := crHourglass;
  123.   locales := TList.Create;
  124.   dictionary.GetLocales(locales);
  125.  
  126.   for i := first to dictionary.LanguageCount - 1 do
  127.   begin
  128.     language := dictionary.Languages[i];
  129.  
  130. {$IFDEF WIN32}
  131.     if (not (ivloShowAllLanguages in options)) and
  132.       ((dictionary.CheckLevel = ivclCodePage) and
  133.        (not dictionary.IsLanguageSupportedByCodePage(language))) or
  134.       ((dictionary.CheckLevel = ivclSystem) and
  135.        (not dictionary.IsLanguageSupportedBySystem(language))) then
  136.     begin
  137.       Continue;
  138.     end;
  139. {$ENDIF}
  140.  
  141.     subs := TStringList.Create;
  142.     dictionary.GetSubLanguages(language, subs, ivloUseNativeLanguage in options);
  143.     for j := 0 to subs.Count - 1 do
  144.     begin
  145.       langId := Integer(subs.Objects[j]);
  146.  
  147.       { Checks if the list already contains the locale }
  148.  
  149.       found := False;
  150.       for k := 0 to listBox.Items.Count - 1 do
  151.       begin
  152.         if Integer(listBox.Items.Objects[k]) = langId  then
  153.         begin
  154.           found := True;
  155.           Break;
  156.         end;
  157.       end;
  158.  
  159.       if found then
  160.         Continue;
  161.  
  162.       { Adds the locale to the list }
  163.  
  164.       if ivloUseNativeLanguage in options then
  165.         displayName := ivdnNative
  166.       else
  167.         displayName := ivdnTranslated;
  168.  
  169.       for k := 0 to locales.Count - 1 do
  170.       begin
  171.         locale := TIvLocale(locales[k]);
  172.         if locale.Locale = langId then
  173.         begin
  174.           ListBox.Items.AddObject(
  175.             locale.GetDisplayName(displayName, dictionary),
  176.             TObject(langId));
  177.           Break;
  178.         end;    
  179.       end;
  180.     end;
  181.     subs.Free;
  182.   end;
  183.  
  184.   dictionary.FreeList(locales);
  185.   Screen.Cursor := crDefault;
  186.  
  187.   for i := 0 to listBox.Items.Count - 1 do
  188.     if dictionary.Locale = Integer(listBox.Items.Objects[i]) then
  189.     begin
  190.       ListBox.ItemIndex := i;
  191.       Break;
  192.     end;
  193. end;
  194.  
  195. function TIvSubLanguageSelectDialog.GetLocale: Integer;
  196. begin
  197.   Result := Integer(ListBox.Items.Objects[ListBox.ItemIndex]);
  198. end;
  199.  
  200. procedure TIvSubLanguageSelectDialog.ListBoxDblClick(Sender: TObject);
  201. begin
  202.   Close;
  203.   ModalResult := idOK;
  204. end;
  205.  
  206. procedure TIvSubLanguageSelectDialog.HelpButtonClick(Sender: TObject);
  207. begin
  208.   Application.HelpContext(HelpContext);
  209. end;
  210.  
  211. procedure TIvSubLanguageSelectDialog.FormActivate(Sender: TObject);
  212. begin
  213.   if HelpContext = 0 then
  214.     HelpButton.Hide;
  215. end;
  216.  
  217. end.
  218.